public class Main {
    public static void main(String[] args) {
        // 创建水果集合对象
        FruitCollection fruitCollection = new FruitCollection();

        // 向水果集合中添加水果对象
        fruitCollection.add(new Apple());

        // 创建水果迭代器对象
        FruitIterator iterator = fruitCollection.iterator();

        // 遍历水果集合并输出水果信息
        while (iterator.hasNext()) {
            Fruit fruit = iterator.next();
            System.out.println("水果名称：" + fruit.getName() + "，水果价格：" + fruit.getPrice());
        }

        // 创建苹果工厂对象并创建苹果对象
        FruitFactory factory = new AppleFactory();
        Fruit apple = factory.createFruit();

        // 创建苹果的折扣装饰器对象
        FruitDecorator decorator = new DiscountFruitDecorator(apple);

        // 输出苹果、苹果折扣、通过适配器转换得到的第三方水果信息
        System.out.println("苹果名称：" + apple.getName() + "，苹果价格：" + apple.getPrice());
        System.out.println("苹果（打折）名称：" + decorator.getName() + "，苹果（打折）价格：" + decorator.getPrice());
        System.out.println("第三方水果名称：" + new ThirdPartyFruitAdapter(new ThirdPartyFruitImpl()).getName()
                + "，第三方水果价格：" + new ThirdPartyFruitAdapter(new ThirdPartyFruitImpl()).getPrice());

        // 创建水果观察者对象
        FruitObserver observer = new FruitObserverImpl();

        // 创建可观察的水果对象
        FruitObservable observable = new FruitObservable();

        // 向可观察的水果对象中添加水果观察者
        observable.attach(observer);

        // 发送通知消息
        observable.notifyObservers(decorator);

        // 获取水果管理员对象实例
        FruitManager manager = FruitManager.getInstance();

        // 向水果管理员中添加水果
        manager.addFruit(decorator);
    }
}